<#if invalid?? && invalid>
<div class="alert alert-danger" role="alert">
	<strong>警告！</strong>
	无效的招标信息！
</div>
<#elseif no_user?? && no_user>
<div class="alert alert-danger" role="alert">
	<strong>警告！</strong>
	系统中尚未配置接收用户！
</div>
<#else>
<link rel="stylesheet" href="${request.contextPath}/app/flow/css/flow.css">
<form class="send-with-user-form" action="${request.contextPath}/flow/send-with-user" method="post" enctype="multipart/form-data">
	<input type="hidden" name="type" value="${type}">
	<input type="hidden" name="id" value="${id}">
	<input type="hidden" name="status" value="${status}">
	<input type="hidden" name="" value="">
	<input type="hidden" name="" value="">
	<div class="row">
		<div class="col-md-12">
			<table class="table table-bordered" style="border: none;">
				<tr>
					<th class="text-center text-primary">待选人员</th>
					<th class="text-center" rowspan="2" style="width: 45px; vertical-align: middle; border: none;">
						<i class="icon-arrow-right"></i>
						<br>
						<i class="icon-arrow-left"></i>
					</th>
					<th class="text-center text-danger">已选人员</th>
				</tr>
				<tr>
					<td class="text-center">
						<div class="for-add ${single?string('single','')}">
							<#if users> <#list users as u>
							<div class="item" data-id="${u.id}">${u.name}</div>
							</#list> </#if>
						</div>
					</td>
					<td class="text-center">
						<div class="added"></div>
					</td>
				</tr>
			</table>
		</div>
	</div>
</form>
<hr>
<div class="row">
	<div class="col-md-12 text-right">
		<div class="btn btn-danger btn-sm btn-submit">发送</div>
		&nbsp;
		<div class="btn btn-default btn-sm" onclick="$.suredy.closeModal();">取消</div>
	</div>
</div>
<script type="text/javascript">
	$(function() {
		var synUser = function() {
			var forAdd = $('form.send-with-user-form .for-add .item.active');
			var added = $('form.send-with-user-form .added');

			// 清空已选人员
			$('form.send-with-user-form .added').html('');

			// 添加已选人员
			forAdd.each(function(i) {
				var $this = $(this);

				added.append('<input type="hidden" name="userIds" value="' + $this.data('id') + '"></input><div class="item text-danger">' + $this.text() + '</div>');
			});
		};

		// 待选点击
		$('form.send-with-user-form .for-add').on('click', '.item', function() {
			var $this = $(this);
			var forAdd = $('form.send-with-user-form .for-add');

			// 单选
			if (forAdd.hasClass('single')) {
				$('.item', forAdd).removeClass('active');
			}

			if ($this.hasClass('active'))
				$this.removeClass('active');
			else
				$this.addClass('active');

			synUser();
		});

		// 提交表单
		$('.btn.btn-submit').on('click', function() {
			var form = $('form.send-with-user-form');

			// 校验表单
			if ($('.added .item').length <= 0) {
				alert('必须选择人员进行发送！');
				return false;
			}

			var $this = $(this);

			if ($this.hasClass('disabled'))
				return false;

			$this.addClass('disabled');

			form.ajaxSubmit({
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						alert(data.msg || '发送操作失败！');
						$this.removeClass('disabled');
						return false;
					}

					$.suredy.refreshContent('${id}', [ '.suredy-tabs' ]);

					$.suredy.closeModal();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('发送操作失败！\n' + errorThrown);
					$this.removeClass('disabled');
					return false;
				}
			});
		});

	});
</script>
</#if>
